version 17
log using stateprod, text replace
set linesize 100
set more off
**************************************************************
* Program purpose:
* Estimate effect of 8 hour day on productivity in US coal.
* Data set = states 1903-1929 from Mineral Resources of US,
* and unionism from Boal (2006).
* Panel estimates with fixed effects for states.
* Pennsylvania anthracite is excluded.
* Time trend or fixed effects for years.
* Some specifications include state-specific trends.
**************************************************************

* Read data =====================================================

use statecoal.dta, clear

* Descriptive statistics of data as read
describe
summarize
tabulate statename

* Compute US annual employment on 8 hours, 9 hours, 10 hours, 
* and other hours for figure 3.
total hrs8 hrs9 hrs10 hrsoth, over (year)

* Generate variables needed for regression ====================

* Transform data to create regressors
generate prod = coal/employ/days
generate lprod = log(prod)
generate ldays = log(days)
generate lemploy = log(employ)
generate mach = coalmach/coal
generate union  = union100/100
generate emp8 = hrs8/employ
generate mytrend = year-1900

label variable lprod "Log output per worker per day"
label variable ldays "Log average days worked"
label variable lemploy "Log total employees"
label variable mach "Fraction of coal mined by machine"
label variable union "Fraction of workers members of the UMWA"
label variable emp8 "Fraction of workers on 8-hour day"
label variable mytrend "Time trend, 1900=zero"

* Clean sample ================================================

* Exclude states with few usable observations and/or inconsistent 
* grouping:  Alaska, Georgia, North Carolina.
drop if  fips==2 | fips==13 | fips==37 

* Exclude Pennsylvania anthracite.
drop if  fips==999

* Exclude observations missing essential data.  For example,
* no hours data are available for 1909.
drop if missing(lprod,mach,hrs8)

list year statename coal employ days prod if prod>8 // Check for outliers.
list year statename employ hrs8 emp8 if emp8>1      // Check for errors.
duplicates report fips year  // There should be no duplicates.

* Compute descriptive statistics of regression sample ===========

* Table 2
summarize prod days emp8 mach union year
tabulate statename   // Panel should be strongly balanced.

* Set up for panel analysis =====================================

sort fips year
xtset fips year
xtdescribe

* Compute effect of 8 hour day on productivity ==================

* Table 3 
xtreg lprod  emp8 mach mytrend, fe vce(cluster fips)
xtreg lprod  emp8 mach union mytrend, fe vce(cluster fips)
xtreg lprod  emp8 mach i.year, fe vce(cluster fips)
xtreg lprod  emp8 mach union i.year, fe vce(cluster fips)
xtreg lprod  emp8 mach i.fips#c.mytrend, fe vce(cluster fips)
xtreg lprod  emp8 mach union i.fips#c.mytrend, fe vce(cluster fips)

* Robustness checks =============================================

* Compute weighted panel estimates.
* Results referenced in text but not presented in any table.
* Weight by employment so that big states count more.
* Note:  Stata requires that weights be constant within the id 
* variable, not varying over time, so must compute mean employment
* for each state.
by fips: egen mywt = mean(ln(employ)) //weight variable constant over time
xtreg lprod  emp8 mach mytrend [aweight=mywt], fe vce(cluster fips)
xtreg lprod  emp8 mach union mytrend [aweight=mywt], fe vce(cluster fips)
xtreg lprod  emp8 mach i.year [aweight=mywt], fe vce(cluster fips)
xtreg lprod  emp8 mach union i.year [aweight=mywt], fe vce(cluster fips)
xtreg lprod  emp8 mach i.fips#c.mytrend [aweight=mywt], fe vce(cluster fips)
xtreg lprod  emp8 mach union i.fips#c.mytrend [aweight=mywt], ///
  fe vce(cluster fips)

* Compute effect of 8 hour day on days and employment ===========
 
* Effect of 8-hour day on days of operation
xtreg ldays  emp8 mach i.year, fe vce(cluster fips)
xtreg ldays  emp8 mach union i.year, fe vce(cluster fips)

* Effect of 8-hour day on employment
xtreg lemploy  emp8 mach i.year, fe vce(cluster fips)
xtreg lemploy  emp8 mach union i.year, fe vce(cluster fips)

* End program ===================================================
clear
log close
exit


